/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.ctu.android.DriveCommunicator.activities;



import java.util.Timer;
import java.util.TimerTask;

import cz.ctu.android.DriveCommunicator.R;
import cz.ctu.android.DriveCommunicator.dialogs.NewMessageDialog;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.Toast;

/**
 *
 * Main activity is executed after application startup and is responsible for
 * registering listeners, forwarding requests, etc..
 *
 * @author karlos
 */
public class MainActivity extends Activity {

	private ImageButton conversationButton;
	private ImageButton newMessageButton;

	private ImageButton settingsButton;
	private boolean running;

	
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
       conversationButton = (ImageButton)findViewById(R.id.conversationButton);
       conversationButton.setOnClickListener(conversationClickListener);
       newMessageButton = (ImageButton)findViewById(R.id.newMessageButton);
       newMessageButton.setOnClickListener(newMessageOnClickListener);

       settingsButton = (ImageButton) findViewById(R.id.settingsButton);
       settingsButton.setOnClickListener(settingsClickListener);
       running = true;

        // TODO do some logic, register observers, etc...
        /*
        Intent intent = new Intent();
        intent.setClass(this, ConversationActivity.class);
        startActivity(intent);
        finish();
        */
       
       //simulating of receaving new sms - delete if upgrading app to real sms receaving... 
       queveNewMessage();
    }
    
    
    
    private OnClickListener conversationClickListener=new OnClickListener(){

		public void onClick(View v) {
			Intent intent=new Intent(MainActivity.this,ConversationActivity.class);
	        startActivity(intent);
	        
		}
    	
    };
    
    private OnClickListener settingsClickListener=new OnClickListener(){

		public void onClick(View v) {
			Intent intent=new Intent(MainActivity.this,SettingsActivity.class);
	        startActivity(intent);
	        
		}
    	
    };
    
    private OnClickListener newMessageOnClickListener=new OnClickListener(){

		public void onClick(View v) {
			Intent intent=new Intent(MainActivity.this,NewMessageActivity.class);
	        startActivity(intent);
	        
		}
    	
    };
    
  //simulating of receaving new sms - delete if upgrading app to real sms receaving... 
    private void queveNewMessage(){
    	Timer t = new Timer();
		  final Handler handler = new Handler(); 
	        t.schedule(new TimerTask() { 
	                public void run() { 
	                        handler.post(new Runnable() { 
	                                public void run() { 
	                                	showNewMessageDialog();
	                                } 
	                        }); 
	                } 
	        }, 10000);
    }
    //on reaceaving new sms show this panel...
    private void showNewMessageDialog(){
    	NewMessageDialog dialog = new NewMessageDialog(this);
        dialog.requestWindowFeature(Window.FEATURE_OPTIONS_PANEL);
        dialog.show();
    	
    }
    
   
}
